<template>
  <div class="page pd">
    <div class="">
      <div class="fw fs-2">{{document.name}}</div>
      <div v-if="endAtName" class="fs-4 c-gray" style="padding-top: 8px;">截止时间：{{endAtName}}</div>
      <div class="pdh pdt" style="border-bottom: 1px dashed #ddd;"></div>
      <div class="pdt">
        <blocks :value="document.data.blocks"></blocks>
      </div>
    </div>
    <div class="fix-bottom bg-white">
      <div class="weui-flex v-mdl">
        <div class="weui-flex__item bd-r">
          <notify-btn cls="ui btn secondary no-rounder no-border" @hit="onCopy">
            复制并转发
          </notify-btn>
        </div>
        <div class="weui-flex__item">
          <notify-btn cls="ui btn secondary no-rounder no-border" @hit="onModify">
            修改作业
          </notify-btn>
        </div>
      </div>
    </div>
    <page-common></page-common>
  </div>
</template>

<script>
import PageCommon from '@/components/page-common'
import {mapGetters, mapActions} from 'vuex'
import Blocks from '@/components/blocks'
import NotifyBtn from '@/components/notify-btn'
import base from '@/mixins/base'
import * as _app from '@/utils/app'
import * as _helper from '@/utils/helper'
export default {
  mixins: [base],
  components: {
    PageCommon,
    Blocks,
    NotifyBtn
  },
  onShareAppMessage() {
    return {
      title: this.document.name,
      path: '/pages/task-invite/main?taskId=' + this.task.id
    }
  },
  computed: {
    ...mapGetters([
      'loginer'
    ]),
    ...mapGetters('document', [
      'document'
    ]),
    ...mapGetters('task', [
      'task'
    ]),
    dataBlocks () {
    },
    endAtName () {
      if (!this.task) return ''
      if (!this.task.expireAt) return ''
      return _helper.timeName(this.task.expireAt)
    }
  },
  methods: {
    ...mapActions([
      'setBlocks',
    ]),
    ...mapActions('document', [
      'updateName',
      'updateContent',
    ]),
    pre (opt) {
      if (opt === 'copy') {
        this.$store.commit('document/SET_DOCUMENT', {...this.document, id: 0, t: new Date()})
      } else {
        this.$store.commit('document/SET_DOCUMENT', {...this.document, t: new Date()})
      }
      this.$store.commit('document/DOCUMENT_SET_OPERATION', opt)

      this.updateName(this.document.name)

      let content = _app.getContentFromBlocks(this.document.data.blocks)
      this.updateContent(content)

      let mediaBlocks = _app.getMediaBlocksFromBlocks(this.document.data.blocks)
      this.setBlocks(mediaBlocks)
    },
    onCopy () {
      this.pre('copy')
      wx.navigateTo({
        url: '/pages/document-create/main'
      })
    },
    onModify () {
      this.pre('modify')
      wx.navigateTo({
        url: '/pages/document-create/main'
      })
    }
  }
}
</script>

<style scoped>
</style>
